<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: AddRole.php 367 2010-02-06 20:04:08Z steen.rabol@gmail.com $
 *
 */

class AddRole extends PortalAdminPage
{
	public function onLoad($param)
	{
		$this->setAdminPageTitle('Add Role');
	}

	public function saveButtonClicked($sender, $param)
	{
		if($this->IsValid)
		{
			$name	= $this->RoleName->Text;
			$sql	= "insert into tblroles (name) values('$name')";

			try
			{
				$this->DataAccess->createCommand($sql)->execute();
			}
			catch(Exception $e)
			{
				throw new PortalException(0,$e->getMessage());
			}

			$this->gotoPage('Admin.RoleMan');
		}
	}

	public function validateRole($sender,$param)
	{
		try
		{
			$sql 	= "select id from tblroles where name='" . $this->RoleName->Text . "'";
			if($this->DataAccess->createCommand($sql)->queryScalar())
			{
				$param->IsValid	= false;
			}
			else
			{
				$param->IsValid = true;
			}
		}
		catch(Execption $e)
		{
			$param->IsValid = false;
		}
	}
}
?>